<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">

</head>

<body>
    <div id="content"></div>
    <template id="tem1">
        <div>
            <el-table :data="users">
                <el-table-column prop="id" label="编号" width="150">
                </el-table-column>
                <el-table-column prop="username" label="姓名" width="150">
                </el-table-column>
                <el-table-column prop="age" label="年龄" width="150">
                </el-table-column>
                <el-table-column label="操作" width="250">
                    <!-- 自定义列内容需要使用插槽 -->
                    <div slot-scope="scope">
                        <!-- {{scope.row}} -->
                        <!-- {{scope.$index}} -->
                        <el-button type="danger" size="mini" @click="del(scope.row.id)">删除</el-button>
                        <el-button type="primary" size="mini" @click="edit(scope.row.id)">编辑</el-button>
                        <el-button type="success" size="mini" @click="add()">添加</el-button>
                    </div>
                </el-table-column>
            </el-table>
        </div>
    </template>
    <script src="./js/vue.min.js"></script>
    <script src="./js/jquery.min.js"></script>
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script>
        var vm = new Vue({
            el: '#content',
            template: '#tem1',
            data: function () {
                return {
                    users: []
                }
            },
            // 设置created
            created: function () {
                this.getuser()
            },
            methods: {
                // 获取数据
                getuser: function () {
                    var _this = this
                    $.get('/Users/index', function (result) {
                        _this.users = result
                    })
                },
                del: function (id) {
                    if (confirm('确认删除')) {
                        $.get('/Users/del', { id: id }).done(function () {
                            location.reload()
                        })
                    }
                },
                // 编辑
                edit:function(id){
                    location.href='./eledit.html#'+id
                },
                add:function(){
                    location.href='./eladd.html'
                }
            }
        })
    </script>
</body>

</html>